package cn.yunhe.servlet;

import cn.yunhe.entity.LiuYan;
import cn.yunhe.service.LiuYanService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class BianJiServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        PrintWriter out = response.getWriter();

        int lid = Integer.parseInt(request.getParameter("lid"));
        String title = request.getParameter("title");
        String context = request.getParameter("context");
        LiuYan liuYan = new LiuYan(lid, title, context);

        LiuYanService liuYanService = new LiuYanService();
        if (liuYanService.updateLiuYan(liuYan)) {
            out.print("<script>alert('修改成功!!!');location.href='LiuYanListServlet';</script>");
        }else{
            out.print("<script>alert('修改失败,请联系管理员!!!');location.href='LiuYanListServlet';</script>");
        }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
